#include<bits/stdc++.h>
using namespace std;

queue<char>q;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	for(int i = 0; i < s.size(); ++i) {
		bool flag = false;
		if(s[i] == ')') {
			if(q.front() == '(') {
				q.pop();
				flag = true;
			}
		}
		if(flag == false)q.push(s[i]);	
	}
	string ret;
	
	while(q.size()) {
		ret += q.front();
		q.pop();
	}
	//reverse(ret.begin(), ret.end());
	
//	cout << ret << '\n'; 
	int ans = 0, t= 0;
	
	for(int i = 0; i < ret.size(); ++i) {
		if(ret[i] == ')' && ret[i + 1] == '(')ans += 2, i++;
		else t++;
	}
	cout << ans + t / 2 << '\n';
	return 0;
}
